from  AutoTesting.readFromScript import read
from  AutoTesting.test import Browser
import AutoTesting.settings as s
import unittest
import time
import os
from BeautifulReport import BeautifulReport


class TestCaseCollection(unittest.TestCase):

	def testCase(self):
		''''''
		result = Browser.test()
		time.sleep(s.T02STEPTIME)
		if result:
			print(s.T04PASSPRINTINFORMATION%Browser.data)
			self.assertTrue(True,msg="执行成功")
		else:
			print(s.T04FAILEPRINTINFORMATION%Browser.data)
			self.assertTrue(False,msg="执行失败")

	

def executeTestCase():
	print('正在读取文件数据')
	script = read()
	# print(script)

	Browser.set(script)
	suite = unittest.TestSuite()
	filename = time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime())
	print('正在加载测试用例')
	for i in range(len(script)):
		suite.addTest(TestCaseCollection("testCase"))
	runner = BeautifulReport(suite)
	print("测试用例共计:",len(script),"条")
	print('测试用例执行中...')
	runner.report(filename=filename,description='测试报告',log_path=s.T99REPORT)
	time.sleep(s.T02ENDTIME)
	Browser.quit()
	print('脚本运行完毕')



